package com.iterator;

import java.util.Iterator;
import java.util.List;

public class OutPutImpl {

    //学院集合
    List<College> colleages;

    public OutPutImpl(List<College> colleageList){
        this.colleages = colleageList;
    }

    // 遍历所有的学院，然后调用printDepartment 输出各个学院的系
    public void printCollege() {
        // 从collegeList 取出所有学院，Java中的List已经实现了Iterator
        Iterator<College> iterator = colleages.iterator();

        while (iterator.hasNext()){
            // 取出一个学院
            College colleage = iterator.next();
            System.out.println("======"+colleage.getName()+"=======");
            printDepartment(colleage.createIterator()); //得到对应的迭代器
        }
    }

    // 输出学院的系

    public void printDepartment(Iterator iterator){
        while(iterator.hasNext()){
            Department d = (Department) iterator.next();
            System.out.println(d.getName());
        }
    }
}
